//
//  Order.m
//  iFlower
//
//  Created by Tho Hoang on 10/28/10.
//  Copyright 2010 iNIL.me. All rights reserved.
//

#import "Order.h"
#import "Product.h"

NSString* const kOrderDataTemplate = @"login=%@&s_address=%@&s_address2=%@&s_phone=%@&s_country=%@&s_state=%@&s_zipcode=%@&s_fax=%@&s_city=%@&s_countryname=%@&s_statename=%@&s_firstname=%@&s_lastname=%@&total_cost=%3.2f&subtotal=%3.2f&shipping_cost=%3.2f&shippingid=%d&tax_cost=%3.2f&discount=%3.2f&delivery_date=%@&flowers_for=%@&deliver_to=%@&message=%@&instructions=%@&is_funeral=%@&funeralHour=%@&funeralMin%@&deceased_name=%@&terms=Y";

@implementation Order
@synthesize deliveryDate = deliveryDate_;
@synthesize customerNotes = customerNotes_;
@synthesize user=user_;
@synthesize address=address_;
@synthesize basket=basket_;
@synthesize shipping=shipping_;
@synthesize deliveryOptions=deliveryOptions_;

-(NSString*)orderData
{
	NSLog(@"%@",self.user.username);
	NSLog(@"%@",self.address.addressLine1);
	NSLog(@"%@",self.address.addressLine2);
	NSLog(@"%@",self.address.phone);
	NSLog(@"%@",self.address.country);
	NSLog(@"%@",self.address.state);
	NSLog(@"%@",self.address.zipCode);
	NSLog(@"%@",self.address.fax); 
	NSLog(@"%@",self.address.city);
	NSLog(@"%@",self.address.country);
	NSLog(@"%@",self.address.state);
	NSLog(@"%@",self.address.firstName);
	NSLog(@"%@",self.address.lastName);
	NSLog(@"%f",self.basket.totalCost);
	NSLog(@"%f",self.basket.subTotalCost); 
	NSLog(@"%f",self.basket.shippingFee);
	NSLog(@"%d",self.shipping.shippingId);
	NSLog(@"%f",self.basket.discount);
	NSLog(@"%@",self.deliveryDate);
	NSLog(@"flowers_for%@",self.deliveryOptions.flowers_for);
	NSLog(@"deliver_to%@",self.deliveryOptions.deliver_to);
	NSLog(@"message%@",self.deliveryOptions.message);
	NSLog(@"instructions%@",self.deliveryOptions.instructions);
	NSLog(@"is_funeral%@",self.deliveryOptions.is_funeral);
	NSLog(@"funeralHour%@",self.deliveryOptions.funeralHour);
	NSLog(@"funeralMin%@",self.deliveryOptions.funeralMin);
	NSLog(@"deceased_name%@",self.deliveryOptions.deceased_name);
	
	NSString* orderStr= [NSString stringWithFormat:kOrderDataTemplate, self.user.username,
			self.address.addressLine1,self.address.addressLine2,self.address.phone,self.address.country, self.address.state, self.address.zipCode, self.address.fax, self.address.city,
			self.address.country, self.address.state, self.address.firstName, self.address.lastName, self.basket.totalCost,self.basket.subTotalCost, 
			self.basket.shippingFee,self.shipping.shippingId,0.0,self.basket.discount,self.deliveryDate, self.deliveryOptions.flowers_for, self.deliveryOptions.deliver_to,
			self.deliveryOptions.message, self.deliveryOptions.instructions, self.deliveryOptions.is_funeral, self.deliveryOptions.funeralHour, self.deliveryOptions.funeralMin, self.deliveryOptions.deceased_name];
	NSString* productStr = [[NSString alloc] initWithString:@""];
	int i=0;
	for (Product* p in self.basket.products) {
		/*productStr=[productStr stringByAppendingFormat:@"&product=%@",p.product];
		productStr=[productStr stringByAppendingFormat:@"&amount=%d",p.amount];
		productStr=[productStr stringByAppendingFormat:@"&price=%.2f",p.price];
		productStr=[productStr stringByAppendingFormat:@"&provider=%@",p.provider];
		productStr=[productStr stringByAppendingFormat:@"&productcode=%@",p.productCode];
		productStr=[productStr stringByAppendingFormat:@"&productid=%@",p.productId];*/
		productStr=[productStr stringByAppendingFormat:@"&pproduct[]=%@",p.product];
		productStr=[productStr stringByAppendingFormat:@"&pamount[]=%d",p.amount];
		productStr=[productStr stringByAppendingFormat:@"&pprice[]=%.2f",p.price];
		productStr=[productStr stringByAppendingFormat:@"&pprovider[]=%@",p.provider];
		productStr=[productStr stringByAppendingFormat:@"&pproductcode[]=%@",p.productCode];
		productStr=[productStr stringByAppendingFormat:@"&pproductid[]=%@",p.productId];
		i++;
	}
	orderStr = [orderStr stringByAppendingString:productStr];
	//productStr release];
	NSLog(@"order data:%@",orderStr);
	return orderStr;
}

@end
